{extend name="adminblue/base" /}
{block name="resources"/}{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>物流公司名称：</dt>
		<dd>
			<p>
				<input id="company_name" type="text" value="{$expressCompany.company_name}" class="input-common">
			</p>
			<p class="error">请输入物流公司名称</p>

		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>物流公司编号：</dt>
		<dd>
			<p><input id="express_no" type="text" value="{$expressCompany.express_no}" class="input-common"></p>
			<p class="error">请输入物流公司编号</p>
		</dd>
	</dl>
	<dl>
		<dt>联系电话：</dt>
		<dd>
			<p><input id="phone" type="text" value="{$expressCompany.phone}" class="input-common"></p>
			<p class="error">联系电话格式不正确</p>
		</dd>
	</dl>
	<dl>
		<dt>物流公司logo：</dt>
		<dd>
			<div class="upload-btn-common">
				<div>
					<input class="input-file" name="file_upload" id="uploadLogo" type="file" onchange="imgUpload(this);" title="上传">
					<input type="hidden" id="logo" value="{$expressCompany.express_logo}">
				</div>
				
				<input type="text" id="text_logo" class="input-common" readonly="readonly" value="{$expressCompany.express_logo}">
				<em>上传</em>								
				<img id="preview_logo" src="__STATIC__/blue/img/upload-common-select.png" data-src="{:__IMG($expressCompany.express_logo)}" data-html="true" data-container="body" data-placement="top" data-trigger="manual" data-original-title="" title="">
			</div>
			<p class="hint">
				建议使用<i class="important-note">宽100</i>像素-<i class="important-note">高100</i>像素内的<i class="important-note">GIF</i>或<i class="important-note">PNG</i>透明图片；点击下方"保存"按钮后生效。
			</p>
			<p class="error">请上传图片</p>
		</dd>
	</dl>
	<dl>
		<dt>排序：</dt>
		<dd>
			<p><input id="orders" type="number" value="{$expressCompany.orders}" class="input-common harf"></p>
			<p class="error">请输入排列序号</p>
		</dd>
	</dl>
	<dl>
		<dt>是否启用物流：</dt>
		<dd><input id="is_enabled" type="checkbox" class="checkbox" {if condition="$expressCompany.is_enabled eq 1"}checked="checked"{/if} /></dd>
	</dl>
	
	<dl>
		<dt>是否设置为默认：</dt>
		<dd><input id="is_default" type="checkbox" class="checkbox" {if condition="$expressCompany.is_default eq 1"}checked="checked"{/if}/></dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="updataExpressCompanyAjax();">保存</button>
			<button class="btn-common-cancle btn-big" onclick="window.location.href = window.history.go(-1);" >返回</button>
		</dd>
	</dl>

</div>
<input type="hidden" id="co_id" value="{$expressCompany.co_id}">
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//模块输入信息验证
function verify(company_name,express_no,phone) {
	if (company_name == '') {
		$("#company_name").parent().next().show();
		$("#company_name").focus();
		return false;
	}else{
		$("#company_name").parent().next().hide();
	}
	
	if (express_no == '') {
		$("#express_no").parent().next().show();
		$("#express_no").focus();
		return false;
	} else {
		$("#express_no").parent().next().hide();
	}
	
	return true;
}

//添加物流公司
function updataExpressCompanyAjax() {
	var company_name = $("#company_name").val();
	var express_no = $("#express_no").val();
	var company_logo = $("#logo").val();
	var phone = $("#phone").val();
	var orders = $("#orders").val();
	var co_id = $("#co_id").val();
	var is_default = 0;
		if($("#is_enabled").prop("checked")){
		var is_enabled = 1;
	}else{
		var is_enabled = 0;
	}
	if($("#is_default").prop("checked")){
		 is_default = 1;
	}
	if(!verify(company_name,express_no,phone)){
		return false;
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/express/updateexpresscompany')}",
		data : {
			'company_name' : company_name,
			'express_no' : express_no,
			'express_logo' : company_logo,
				'phone' : phone,
			'is_enabled' : is_enabled,
			'orders':orders,
			'co_id':co_id,
			'is_default':is_default
		},
		success : function(data) {
			if (data['code'] > 0) {
				showTip(data["message"],'success');
				location.href = __URL(ADMINMAIN + '/express/expresscompany');
			} else {
				showTip(data["message"],'error');
			}
		}
	});
}

//图片上传
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADEXPRESS };
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#imglogo").attr("src",__IMG(res.data));
			$("#logo").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}
</script>
{/block}